package router

import (
	"github.com/gin-gonic/gin"
	"github.com/go-gin-admin/controller"
	"github.com/go-gin-admin/middleware"
)

// 统一注册路由
func RegisterRoutes() *gin.Engine {

	r := gin.New()
	r.Use(middleware.Cors)
	r.GET("/login", controller.LoginByUserNameAndPassWord)
	r.POST("/upload", controller.Upload)

	// 项目出现
	adminRouter := r.Group("/api/admin", middleware.GinLogger(middleware.Logger), middleware.GinRecovery(middleware.Logger, true))
	adminRouter.Use(middleware.JWTAuthMiddleware(), middleware.AuthCheckRole())
	{
		adminRouter.GET("/getInfo", controller.GetInfo)

		// 字典
		adminRouter.POST("/insertDict", controller.AddDict)
		adminRouter.GET("/getDictList", controller.GetDict)
		adminRouter.PUT("/updateDict", controller.UpdateDict)
		adminRouter.DELETE("/removeDict/:id", controller.RemoveDict)

		// 字典选项
		adminRouter.POST("/insertDictItem", controller.AddDictItem)
		adminRouter.PUT("/updateDictItem", controller.UpdateDictItem) // 修改字典选项
		adminRouter.DELETE("/removeDictItem/:id", controller.RemoveDictItem)
		adminRouter.GET("/getDictItemList", controller.GetDictItemList)
		adminRouter.GET("/getDictItems", controller.GetDictItems)

		// 部门接口
		adminRouter.POST("/addDept", controller.AddDept)
		adminRouter.GET("/getDeptTree", controller.GetDeptTree)
		adminRouter.PUT("/updateDept", controller.UpdateDept)
		adminRouter.DELETE("/deleteDept/:deptId", controller.DeleteDept)

		// 菜单接口
		adminRouter.POST("/addMenu", controller.AddMenu)
		adminRouter.GET("/getMenuTree", controller.GetMenuTree)
		adminRouter.GET("/getMenuTreeByRoleKey", controller.GetMenuTreeByRoleKey) // 根据角色获取角色所拥有的菜单
		adminRouter.PUT("/updateMenu", controller.UpdateMenu)
		adminRouter.DELETE("/deleteMenu/:menuId", controller.DeleteMenu)
		adminRouter.GET("/getMenuByRoleId", controller.GetMenuByRoleId)
		adminRouter.GET("/getMenuElementUiTree", controller.GetMenuElementUiTree)

		// 岗位
		adminRouter.POST("/addJob", controller.AddJob)
		adminRouter.GET("/getJobList", controller.GetJobList)
		adminRouter.PUT("/updateJob", controller.UpdateJob)
		adminRouter.DELETE("/deleteJob/:id", controller.DeleteJob)
		adminRouter.GET("/getJobAllList", controller.GetJobAllList) // 获取所有的岗位

		// 角色
		adminRouter.POST("/addRole", controller.AddRole)
		adminRouter.GET("/getRoleList", controller.GetRoleList)
		adminRouter.PUT("/updateRole", controller.UpdateRole)
		adminRouter.DELETE("/deleteRole/:roleId", controller.DeleteRole)
		adminRouter.GET("/getAllRoleList", controller.GetAllRoleList)

		// 用户
		adminRouter.POST("/addUser", controller.AddUser)
		adminRouter.GET("/getUserList", controller.GetUserList)
		adminRouter.GET("/getRoleIdsByUserId", controller.GetRoleIdsByUserId)
		adminRouter.PUT("/updateUser", controller.UpdateUser)
		adminRouter.DELETE("/deleteUser/:userId", controller.DeleteUser)
	}

	return r
}
